<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台管理系统</title>
        <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file="Public:header" />
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5.js"></script>
    <![endif]-->
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> 
<body class="">
    <!--<![endif]-->

    <!--顶部菜单-->
<include file="Public:navbar" />

<!--左侧导航条-->
<include file="Public:nav" />

<!--右侧整体区域-->
<div class="content">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="row-fluid">
                <!--右侧栏目区域start-->
                <div class="block">
                    <a class="block-heading" data-toggle="collapse">修改密码</a>
                    <div class="block-body collapse in">

                        <div class="container-fluid" style="margin-top: 10px;">
                            <!--右侧栏目内容区域start-->
                            <div class="row">
                                <!--右侧字段区域start-->
                                <div class="span12" style="margin-top:10px;">
                                    <div id='pop'></div>
                                    <form class="form-horizontal" method="post">
                                        <fieldset>

                                            <div id="legend" class="">
                                                <legend class="">修改登录密码</legend>
                                            </div>

                                            <div class="control-group">

                                                <!-- Text input-->
                                                <label class="control-label" for="input01">当前密码</label>
                                                <div class="controls">
                                                    <input type="password" placeholder="当前密码" name="user_pwd" class="input-xlarge">
                                                    <p class="help-block">请输入当前密码</p>
                                                </div>
                                            </div>

                                            <div class="control-group">

                                                <!-- Text input-->
                                                <label class="control-label" for="input01">新密码</label>
                                                <div class="controls">
                                                    <input type="password" placeholder="新密码" name="new_user_pwd" class="input-xlarge">
                                                    <p class="help-block">请输入新密码</p>
                                                </div>
                                            </div>

                                            <div class="control-group">

                                                <!-- Text input-->
                                                <label class="control-label" for="input01">确认新密码</label>
                                                <div class="controls">
                                                    <input type="password" placeholder="确认新密码" name="new_user_pwd1" class="input-xlarge">
                                                    <p class="help-block">请重复输入新密码</p>
                                                </div>
                                            </div>



                                            <div class="form-actions">
                                                <button type="button" class="btn btn-primary" id="save">保 存</button>&nbsp;&nbsp;
                                                <a class="btn" href="{$pre_url}">返 回</a>
                                            </div>
                                        </fieldset>
                                    </form>
                                </div>
                                <!--右侧字段区域end-->
                            </div>
                            <!--右侧栏目内容区域end-->
                        </div>

                    </div>
                </div>
                <!--右侧栏目区域end-->
            </div>
            <footer>
                <include file="Public:footer" />
            </footer>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        var user_pwd = $('[name=user_pwd]');
        var new_user_pwd = $('[name=new_user_pwd]');
        var new_user_pwd1 = $('[name=new_user_pwd1]');
        $('#save').click(function() {
            if (check_fields()) {
                var data = $('form').serialize();
                $.ajax({
                    type: "POST",
                    url: app_url + "/user/update_password",
                    data: data,
                    dataType: 'json',
                    cache: false,
                    success: function(data) {
                        success(data);
                    },
                    error: function() {
                        error();
                    }
                });
            }
        });


        function check_fields() {
            if (user_pwd.val() == '') {
                success(0);
                return false;
            }

            if (new_user_pwd.val() == '') {
                success(1);
                return false;
            }

            if (new_user_pwd.val() != new_user_pwd1.val()) {
                success(2);
                return false;
            }

            return true;
        }


        function pop_error(str) {
            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>' + str + '</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
        }



        $('#pop').ajaxStart(function() {
            $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                    .fadeIn("slow");
        });

        function success(data) {
            switch (data) {
                case 0:
                    pop_error('请输入当前密码！');
                    user_pwd.focus();
                    break;
                case 1:
                    pop_error('新密码不能为空，请填写新密码！');
                    new_user_pwd.focus();
                    break;
                case 2:
                    pop_error('新密码两次输入的不一致，请重新输入！');
                    new_user_pwd.val('');
                    new_user_pwd1.val('');
                    new_user_pwd.focus();
                    break;
                case 3:
                    pop_error('当前用户信息不存在！');
                    location.href = app_url + "/main";
                    break;
                case 5:
                    $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>密码修改成功！</div>')
                            .fadeIn("slow")
                            .fadeOut(5000);
                    user_pwd.val('');
                    new_user_pwd.val('');
                    new_user_pwd1.val('');
                    break;
                case 4:
                    pop_error('当前登录密码不正确！');
                    user_pwd.val('');
                    user_pwd.focus();
                    break;
                case 6:
                    pop_error('密码修改失败：当前密码与新密码相同，无需进行修改！');
                    user_pwd.val('');
                    new_user_pwd.val('');
                    new_user_pwd1.val('');
                    break;
            }


//        if (data.data == 1) {
//            $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>密码修改成功！</div>')
//                    .fadeIn("slow")
//                    .fadeOut(5000);
//        } else {
//            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>密码修改失败：新密码可能与当前密码相同！</div>')
//                    .fadeIn("slow")
//                    .fadeOut(5000);
//        }
        }


        function error() {
            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
        }
    });
</script>
</body>
</html>


